package com.yztc.love_travel.ui.mainservice.eating.presenter;

import android.util.Log;

import com.yztc.love_travel.bean.EatingBean;
import com.yztc.love_travel.ui.mainservice.eating.model.EatingModelImpl;
import com.yztc.love_travel.ui.mainservice.eating.model.IEatingModel;
import com.yztc.love_travel.ui.mainservice.eating.view.IEatingView;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by My on 2016/11/29.
 */

public class EatingPresenterImpl implements IEatingPresenter{
    private IEatingModel mEatingModel;
    private IEatingView  mEatingView;

    public EatingPresenterImpl(IEatingView mEatingView) {
        mEatingModel = new EatingModelImpl();
        this.mEatingView = mEatingView;
    }


    @Override
    public void getEatingBean(String baseUrl,final Map<String, Object> params) {
        mEatingModel.getEatingBean(baseUrl,params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<EatingBean>() {
                    @Override
                    public void onCompleted() {
                        mEatingView.loadFinish();
                        Log.e("tag",params.toString());
                    }

                    @Override
                    public void onError(Throwable e) {
                        mEatingView.loadError();

                    }


                    @Override
                    public void onNext(EatingBean eatingBean) {
                        mEatingView.showRegionCultureData(eatingBean);

                    }

                    @Override
                    public void onStart() {
                        super.onStart();
                        mEatingView.loadStart();
                    }
                });
    }
}
